--- title: "异或三角" created: 2025-11-28 tags: - 算法 --- # 异或三角 ## 题目 [异或三角](https://www.lanqiao.cn/problems/1594/learning/) ![[image-efbf7776.png]] ## 思路分析 ![[image-95b8e604.png]] 有n<200 不知道能不能用dfs过一俩组数据 试试 abc能不能相等? 好像可以 a^b^c 如果相等就为0 三角形也可以构成等边 可以 过了一个 跻身95% 正解又是数位dp…… ## 代码实现 ```cpp #include using namespace std; #define endl '\n' vector alls; int T; int path[3]; int cnt=0; void dfs(int u){ if(u==3){ int a=path[0],b=path[1],c=path[2]; if((a^b^c)==0 && a + b > c && a + c > b && b + c > a) cnt++; return; } for(int i=0;i<=alls.size();i++){ path[u]=alls[i]; dfs(u+1); path[u]=0; } } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>T; while(T--){ alls.clear();cnt=0; int n;cin>>n; for(int i=1;i<=n;i++) alls.push_back(i); dfs(0); cout<